<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<style>
    div {
        position: absolute;
        margin-top: 20px;
        border: 1px solid;
        margin-left: 20px;
        border-radius: 20px;
        width: 200px;
        height: 40px;
        background-color: aliceblue;
        text-align: center;
        line-height: 40px;
    }
</style>

<body>
    <div>
    </div>
    <script>
        var div = document.querySelector('div');
        var timer = 3;
        setInterval(function () {
            if (timer == 0) {
                location.href = 'https://www.baidu.com/';

            } else {
                div.innerHTML = '还有' + timer + '秒跳转到百度首页'
                timer--;
            }
        }, 1000);
        // location.assign('href')可以返回原来的页面
        // location.replace('href')无法返回
        // location.href也是无法返回
        // lcation.reload()重新加载页面，如果有参数true，表示强制刷新
    </script>
</body>

</html>